package 笔试2.pdd.four;


//--指令迷宫
public class Main {
    /*只改这里———————————————————————————————————————————————————*/
    static void qian(int i, int j, int[] zl,int k) {
        if(k==zl.length){
            int resi=i+1,resj=j+1;
            System.out.println(resi+","+resj);
            System.out.println();
            return;
        }
        int cZL = zl[k];

        ptIntShuzu(g);
        int x=i+fx[cZL-1][0],y=j+fx[cZL-1][1];

        //停止
        if(x<0||x>=g.length||y<0||y>=g[0].length //越界
                || g[x][y]==6  //vis走过
                || g[x][y]==-1 //障碍
        ) {

            qian(i, j, zl, k + 1);
        }
        else {

            //other全都能走 (con排-1 6 return排2 -> 就剩’0‘)
            step++;
            int t=g[x][y];
            g[x][y] = 6;
            qian(x, y, zl, k + 1);
            step--;
            g[x][y] = t;
        }

    }
    /*—————————————————————————————————————————————————————————*/

    static int[][] g = {
            //1起点 -1障碍 6走过 2终点 0可走
            //停止:-1 6
            //return: 2
            //可走 (0)

            {1,0,1},
            {0,1,0},
            {1,0,0},
    };
    static int[][] G ;
    static int[][] fx = {{-1,0},{1,0},{0,-1},{0,1}};
    public static void main(String[] args) {

        G=new int[g.length][g[0].length];
        //找起点(若固定00起，删掉)
        for (int i=0;i<g.length;i++) {
            for (int j=0;j<g[0].length;j++) {
                if(g[i][j]==1){
                    System.out.println("1");
                    qian(i,j,new int[]{1,2,3},0);
                }
            }
        }
//        ptIntShuzu(G);

//        System.out.println("最少走 "+resMin+" 步");
    }
    static int step=0;
    static int resMin=9999;
    static void ptIntShuzu(int[][] p){
        for (int i = 0; i < p.length; i++) {
            for (int j = 0; j < p[0].length; j++) {
                System.out.print(p[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println("——————————————————————————");
    }
}
